package com.neusoft.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	public static final int ONE_DAY_IN_MILLS = 86400000;

	public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	public static java.util.Date string2UtilDate(String str) {
		Date temp = null;
		try {
			temp = sdf.parse(str);
			return temp;
		} catch (ParseException e) {
			System.out.println("文本格式不正确");
		}
		return null;
	}

	public static java.util.Date string2UtilDate(String str, String fmt) {
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		Date temp = null;
		try {
			temp = sdf.parse(str);
			return temp;
		} catch (ParseException e) {
			System.out.println("文本格式不正确");
		}
		return null;
	}

	public static java.sql.Date string2SqlDate(String str) {
		// String -> java.util.Date
		java.util.Date temp = string2UtilDate(str);
		// java.util.Date -> java.sql.Date
		if (temp != null) {
			return new java.sql.Date(temp.getTime());
		}
		return null;
	}

	public static String date2String(java.util.Date date) {
		return sdf.format(date);
	}

	public static String date2String(java.util.Date date, String fmt) {
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		return sdf.format(date);
	}

	/**
	 * @Description: long类型转换成日期
	 *
	 * @param lo 毫秒数
	 * @return String yyyy-MM-dd HH:mm:ss
	 */
	public static String longToDate(long lo) {
		java.sql.Date date = new java.sql.Date(lo);
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
		return sd.format(date);
	}

}
